/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.edu.fatec.ads.classes;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

/**
 *
 * @author BRUNO
 */
@Entity
public class Emprestimo extends AbstractTO {

    private int codigo;
    private Date dataEmprestimo;
    private Date dataDevolucao;
    private Cartao cartao;
    private Livro livro;

    public Emprestimo() {
    }

    /**
     * @return the codigo
     */
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="cd_emprestimo", length=5)
    public int getCodigo() {
        return codigo;
    }

    /**
     * @param codigo the codigo to set
     */
    public void setCodigo(int codigo) {
        this.codigo = codigo;
    }

    /**
     * @return the dataEmprestimo
     */
    @Temporal(TemporalType.DATE)
    @Column(name="dt_emprestimo", nullable=false)
    public Date getDataEmprestimo() {
        return dataEmprestimo;
    }

    /**
     * @param dataEmprestimo the dataEmprestimo to set
     */
    public void setDataEmprestimo(Date dataEmprestimo) {
        this.dataEmprestimo = dataEmprestimo;
    }

    /**
     * @return the dataDevolucao
     */
    @Temporal(TemporalType.DATE)
    @Column(name="dt_devolucao")
    public Date getDataDevolucao() {
        return dataDevolucao;
    }

    /**
     * @param dataDevolucao the dataDevolucao to set
     */
    public void setDataDevolucao(Date dataDevolucao) {
        this.dataDevolucao = dataDevolucao;
    }

    @ManyToOne(fetch=FetchType.LAZY)
    @Fetch(FetchMode.SELECT)
    @JoinColumn(name="cd_cartao", nullable=false)
    public Cartao getCartao() {
        return cartao;
    }

    public void setCartao(Cartao cartao) {
        this.cartao = cartao;
    }

    @ManyToOne(fetch=FetchType.LAZY)
    @Fetch(FetchMode.SELECT)
    @JoinColumn(name="cd_tombo", nullable=false)
    public Livro getLivro() {
        return livro;
    }

    public void setLivro(Livro livro) {
        this.livro = livro;
    }

    @Transient
    @Override
    public Serializable getPK() {
        return this.getCodigo();
    }

    @Override
    public void setPK(Serializable identifier) {
        this.setCodigo((Integer) identifier);
    }

    @Override
    public String toString() {
        return "Emprestimo[codigo=" + this.getCodigo()
                + ", dataEmprestimo=" + this.getDataEmprestimo()
                + ", dataDevolucao=" + this.getDataDevolucao() + "]";
    }
}
